<?php
/**
 * File: imageproperty.php.
 * Author: zhouzhe@haibao.com
 * Editor: PhpStorm
 * Date: 16/8/22 下午6:15
 * Brief:
 */
namespace haibao\cms\business;

use haibao\cms\model\data\ImageProperty as ImagePropertyData;

class ImageProperty extends \haibao\cms\business\Base{
	public static function updateDownNum($imageId){
		$data = new \haibao\cms\data\ImageProperty();
		if(!$imageId){
			throw new \haibao\cms\business\BusinessException('Id不能为空');
		}
		return $data->updateDownNum($imageId);
	}

	public static function updateClickNum($imageId,$isPc = true,$isFromImageIndex = false){
		if(!$imageId){
			throw new \haibao\cms\business\BusinessException('Id不能为空');
		}
		$data = new \haibao\cms\data\ImageProperty();
		$data->updateClickNum($imageId,$isPc,$isFromImageIndex);
	}
	
	public static function subtractCommentNum($imageId,$isComment = true,$isQuestion = \haibao\comment\model\data\CommentContent::CONTENT_IS_COMMENT,$numInfo = array()){
	    if(!$imageId){
	        throw new \haibao\cms\business\BusinessException('Id不能为空');
	    }
	    $data = new \haibao\cms\data\ImageProperty();
	    $data->subtractCommentNum($imageId,$isComment,$isQuestion,$numInfo);
	}
	
	public static function getPropertyNum($imageId){
		if(!$imageId){
			throw new \haibao\cms\business\BusinessException('Id不能为空');
		}
		$data = new \haibao\cms\data\ImageProperty();
		return $data->getPropertyNum($imageId);
	}
	
	public static function updatePraiseCount($imageId,$userId){
		if(!$imageId){
			throw new \haibao\cms\business\BusinessException('Id不能为空');
		}
		$data = new \haibao\cms\data\ImageProperty();
		$data->updatePraiseCount($imageId);
		\haibao\user\common\ScoreRule::operateScore($userId,\haibao\user\common\ScoreRule::TYPE_PARISE);
	}
	
	public static function updateCommentNum($imageId,$isComment = true,$isQuestion = \haibao\comment\model\data\CommentContent::CONTENT_IS_COMMENT){
		if(!$imageId){
			throw new \haibao\cms\business\BusinessException('Id不能为空');
		}
		$data = new \haibao\cms\data\ImageProperty();
		$data->updateCommentNum((int)$imageId,$isComment,$isQuestion);
	}
	
	public static function updateMarkNum($imageId){
	    $data = new \haibao\cms\data\ImageProperty();
	    if(!$imageId){
	        throw new \haibao\cms\business\BusinessException('Id不能为空');
	    }
	    return $data->updateMarkNum($imageId);
	}
	
	public static function getCommentNum($imagePropertyFilter){
		$data = new \haibao\cms\data\ImageProperty();
		return $data->getOne($imagePropertyFilter);
	}

	/**
	 * 取最热图片
	 */
	public static function getHotImages(){
		$data = new \haibao\cms\data\ImageProperty();
		return $data->getHotImages();
	}
	
	/**
	 * 图片相关的文章或图集
	 * @param int $imageId
	 */
	public static function getRelateList($imageId){
		$data = new \haibao\cms\data\ImageProperty();
		return $data->getRelateList($imageId);
	}

	/**
	 * 扫描二维码相关操作
	 */
	public static function updateScanQrcode($imageId){
		$data = new \haibao\cms\data\ImageProperty();
		$data->updateScanQrcode($imageId);
	}
}